package com.zpc.browser;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author : zpc20 //作者
 * @version : 1.0 // 版本
 * @ClassName : Server  //类名
 * @Description : 服务端  //描述
 * @Date: 2024-12-03  下午 09:52
 */
public class Server {
    public static void main(String[] args) {
        try(
                ServerSocket server = new ServerSocket(8080)
                ){
            System.out.println("My Server started");
            Socket socket = server.accept();
            System.out.println("Client connected "+socket.getInetAddress().getHostAddress());
            InputStream input = socket.getInputStream();
            System.out.println("accept data: ");
            while(true){
                int i = input.read();
                if (i == -1) break;
                System.out.print((char) i);
            }
        }catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
